//
//  MSGetCoinTableViewController.m
//  SocietySale
//
//  Created by Mike on 16/11/30.
//  Copyright © 2016年 Mike. All rights reserved.
//

#define btnWidth      90

#import "MSGetCoinTableViewController.h"

@interface MSGetCoinTableViewController ()
//section头部标题
@property(nonatomic,copy)NSArray *sectionTitleArray;
@property(nonatomic,copy)NSArray *sectionBtnArray;
@end

@implementation MSGetCoinTableViewController

- (void)viewDidLoad{
    [super viewDidLoad];
    
    self.sectionTitleArray = @[@"交易获得换游币：",@"邀请通讯录获得换游币：",@"分享获得换游币："];
    self.sectionBtnArray = @[@"去发布交易",@"邀请通讯录好友",@""];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 0;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 40;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREENWIDTH, 30)];
    bgView.backgroundColor = [UIColor whiteColor];
    
    UIView *blueView = [[UIView alloc]initWithFrame:CGRectMake(0, 7.5, 4, 15)];
    blueView.backgroundColor = kBlueColor;
    [bgView addSubview:blueView];
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(16, 0, 260, 30)];
    titleLabel.text = self.sectionTitleArray[section];
    titleLabel.textColor = kDarkGrayColor;
    titleLabel.font = HeitiFont(14);
    [bgView addSubview:titleLabel];
    
    return bgView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section == 2) {
        return 150;
    }
    return 60;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREENWIDTH, 150)];
    
    if (section == 2){
        NSArray *imageArray = @[@"weixin",@"pengyouquan",@"weibo",@"qq",@"qzone",@"tengxunweibo"];
        NSArray *titleArray = @[@"微信好友",@"朋友圈",@"新浪微博",@"QQ好友",@"QQ空间",@"腾讯微博"];
        
        for (int i=0; i<6; i++) {
            GXButton *btn = [GXButton buttonWithType:UIButtonTypeCustom];
            btn.frame = CGRectMake((SCREEN_WIDTH-270)/2+btnWidth*(i%3), 0+i/3*85, btnWidth, 70);
            btn.tag = 100+i;
            btn.relayout = YES;
            btn.imageViewFrame = CGRectMake((btnWidth-44)/2.0, 0, 44, 44);
            btn.titleLabelFrame = CGRectMake(0, 44+10, btn.width, 15);
            btn.titleLabel.textAlignment = NSTextAlignmentCenter;
            btn.titleLabel.font = [UIFont fontWithName:@"STHeitiSC-Light" size:12];
            [btn setTitleColor:UIColorFromRGB(0x000000) forState:UIControlStateNormal];
            [btn setTitle:titleArray[i] forState:UIControlStateNormal];
            [btn setImage:[UIImage imageNamed:imageArray[i]] forState:UIControlStateNormal];
            [btn addTarget:self action:@selector(goClick:) forControlEvents:UIControlEventTouchUpInside];
            [bgView addSubview:btn];
        }
    }
    else{
        UIButton *goBtn = [[UIButton alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-150)/2, 0, 150, 30)];
        goBtn.tag = 10+section;
        goBtn.titleLabel.font = HeitiFont(16);
        goBtn.layer.borderWidth = 1;
        goBtn.layer.cornerRadius = 2;
        goBtn.layer.borderColor = kNormalGray.CGColor;
        [goBtn setTitle:self.sectionBtnArray[section] forState:UIControlStateNormal];
        [goBtn setTitleColor:kLightBlackColor forState:UIControlStateNormal];
        [goBtn addTarget:self action:@selector(goClick:) forControlEvents:UIControlEventTouchUpInside];
        [bgView addSubview:goBtn];
    }
    
    return bgView;
}

- (void)goClick:(UIButton*)btn{
    if ([self.delegate respondsToSelector:@selector(selectBtnWithIndex:)]) {
        [((id<MSGetCoinTableDelegate>)self.delegate) selectBtnWithIndex:btn.tag];
    }
}

@end
